package com.hankol.feature_wine_meal.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.hankol.feature_wine_meal.R;

import org.w3c.dom.Text;

/**
 * @description
 * @author 关忆北、
 * @time 2022/7/3 3:11 下午
 */
public class ShareWineMealPosterAdapter extends RecyclerView.Adapter<ShareWineMealPosterAdapter.PosterViewHolder> {

    private OnItemClickListener listener;

    public void setListener(OnItemClickListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    public PosterViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new PosterViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_share_wine_meal, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull PosterViewHolder holder, int position) {
        holder.mLlReport.setVisibility(View.GONE);
        holder.mLlWxIcon.setOnClickListener(view -> {
            if (listener != null) listener.onClick(0);
        });
        holder.mLlWxMoment.setOnClickListener(view -> {
            if (listener != null) listener.onClick(1);
        });
        holder.mLlDownload.setOnClickListener(view -> {
            if (listener != null) listener.onClick(2);
        });
        holder.mLlReport.setOnClickListener(view -> {
            if (listener != null) listener.onClick(3);
        });

    }

    @Override
    public int getItemCount() {
        return 1;
    }

    public interface OnItemClickListener {
        void onClick(int position);
    }

    public static class PosterViewHolder extends RecyclerView.ViewHolder {
        private final LinearLayout mLlWxIcon;
        private final LinearLayout mLlWxMoment;
        private final LinearLayout mLlDownload;
        private final LinearLayout mLlReport;
        private final TextView tvDownloadName;

        public PosterViewHolder(@NonNull View itemView) {
            super(itemView);
            mLlWxIcon = (LinearLayout) itemView.findViewById(R.id.ll_wx_icon);
            mLlWxMoment = (LinearLayout) itemView.findViewById(R.id.ll_wx_moment);
            mLlDownload = (LinearLayout) itemView.findViewById(R.id.ll_download);
            mLlReport = (LinearLayout) itemView.findViewById(R.id.ll_report);
            tvDownloadName = (TextView) itemView.findViewById(R.id.tv_download_name);
            tvDownloadName.setText("保存到相册");
        }
    }
}
